package com.example.hehecat.yuejian1.mvp.presenter;

import com.example.hehecat.yuejian1.mvp.contract.ActivityInfoContract;
import com.example.hehecat.yuejian1.mvp.model.ActivityInfoModel;
import com.example.hehecat.yuejian1.mvp.model.bean.SuccessBean;
import com.example.hehecat.yuejian1.ui.fragment.ActivityInfoFragment;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ActivityInfoPresenter implements ActivityInfoContract.Presenter {
    private ActivityInfoModel model;
    private ActivityInfoFragment view;

    public ActivityInfoPresenter(ActivityInfoFragment view) {
        this.view = view;
        model = new ActivityInfoModel();
    }



    @Override
    public void activityEnroll(int activity_id, int user_id) {
        model.activityEnroll(activity_id, user_id, new Callback<SuccessBean>() {
            @Override
            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                if (response.body().getSuccess() != -1) {
                    view.showMsg("报名成功！");
                } else {
                    view.showMsg(response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<SuccessBean> call, Throwable t) {
                view.showMsg("activityEnroll"+t.getMessage());
            }
        });
    }

    @Override
    public void collectActivity(int activity_id, int user_id) {
        model.collectActivity(activity_id, user_id, new Callback<SuccessBean>() {
            @Override
            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                if (response.body().getSuccess() == 1) {
                    view.showMsg("收藏成功");
                } else if(response.body().getSuccess() == 0) {
                    view.showMsg("取消收藏");
                } else {
                    view.showMsg(response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<SuccessBean> call, Throwable t) {
                view.showMsg("collectActivity"+t.getMessage());
            }
        });
    }

    @Override
    public void isActivityCollect(int activity_id, int user_id) {
        model.isActivityCollect(activity_id, user_id, new Callback<SuccessBean>() {
            @Override
            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                if (response.body().getSuccess()==1) {
                    view.setCollect();
                }else if (response.body().getSuccess()==0) {
                    view.setUnCollect();
                }else {
                    view.showMsg("操作失败");
                }
            }

            @Override
            public void onFailure(Call<SuccessBean> call, Throwable t) {
                view.showMsg("isActivityCollect"+t.getMessage());
            }
        });
    }
}
